package com.pwx.student.web.controller;


import com.pwx.student.common.ResponseResult;
import com.pwx.student.service.IRcStudentService;
import com.pwx.student.utils.TokenUtils;
import com.pwx.student.vo.input.CourseInputVo;
import com.pwx.student.vo.input.StudentInfoInputVo;
import com.pwx.student.vo.output.CourseOutputVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author saber
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/rc-student")
public class RcStudentController {

    @Autowired
    private IRcStudentService irs;

    @PostMapping("/searchCourse")
    public ResponseResult searchCourse(CourseInputVo inputVo, HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        inputVo.setUserId(studentId);

        return irs.searchCourse(inputVo);
    }

    @GetMapping("/choseCourse/{courseId}")
    public ResponseResult choseCourse(@PathVariable("courseId") Integer courseId, HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irs.choseCourse(courseId,studentId);
    }

    @GetMapping("/showInfo")
    public ResponseResult showInfo(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irs.showInfo(studentId);
    }

    @PostMapping("/changeInfo")
    public ResponseResult changeInfo(StudentInfoInputVo inputVo, HttpServletRequest request){
        System.out.println("====================");
        System.out.println(inputVo);
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irs.changeInfo(inputVo,studentId);
    }

}
